<?php


namespace App\Api\Controllers;


use App\Models\Balance;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\Orders;
use App\Models\Pay\WxNotify;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Yansongda\Pay\Log;
use Yansongda\Pay\Pay;

class PayController extends Controller
{
    public function order(Request $request)
    {
        $input = $request->only([
            'order_id',
        ]);
        $validator = Validator::make($input, [
            'order_id' => 'required',
        ]);
        if ($validator->fails()) {
            return $this->responseFailed($validator->errors()->first());
        }
        try {
            $data = Balance::pay($request);
            return $this->responseData($data);
        }catch (\Exception $e){
           return $this->responseFailed($e->getMessage());
        }
    }

    public function wxNotify(Request $request)
    {
        try{
            return WxNotify::verify();
        } catch (\Exception $e) {
            Log::debug('Wechat notify error', $e->getMessage());
            return $this->responseFailed($e->getMessage());
        }
    }
}